<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Request;
class Auth extends Base{

    /**
    *角色列表
     */
    public function roleList(){
        $row = Db::table("auth_group")->paginate(5);
        $page = $row->render();
        $this->assign("row",$row);
        $this->assign("page",$page);
        return view();
    }

    //角色添加
    public function addrole(){
        return view();
    }

    //添加数据
    public function edit(){
        $request = Request::instance()->post();
        $data = array();
        $data["title"] = $request['roleName'];
        $data["rules"] = $request['grant'];
        $data["status"] = 1;
         
        Db::table("auth_group")->insert($data);
        return json_encode(1);
        exit;
    }

    //权限分配
    public function staff(){
          $row = Db::table("staff")
            ->join("auth_group_access","auth_group_access.uid = staff.staff_id")
            ->join("auth_group","auth_group.id = auth_group_access.group_id")
            ->select();
        $this->assign("row",$row);
        return view();
    }

    //权限修改
    public function update(){
        $request = Request::instance()->get();
        $id = $request['id'];
        $row = Db::table("auth_group")->select();
        $this->assign("id",$id);
        $this->assign("row",$row);
        return view();
    }

    public function doupdate(){
        $request = Request::instance()->post();
        $id = $request['id'];
        $pid = $request['auth'];
        $data = [
            "uid" => $id,
            "group_id" => "$pid"
        ];
        $row = Db::table("auth_group_access")->where("uid = $id")->find();
        if($row == null){
            Db::table("auth_group_access")->insert($data);
            return view("isto");
        }else{
            Db::table("auth_group_access")->where("uid = $id")->update($data);
            return view("isto");
        }
    }























}